package huoye.shops.huoye.operation.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import butterknife.BindView;
import huoye.shops.R;
import huoye.shops.base.APIUrls;
import huoye.shops.huoye.operation.model.DiscountCancelData;
import huoye.shops.huoye.operation.model.GoodInfo;
import huoye.shops.huoye.operation.model.ManageEventData;
import huoye.shops.huoye.operation.model.QueueShops;
import huoye.shops.utils.StockUtils;
import huoye.shops.widget.RoundImageView;

import static huoye.shops.huoye.operation.fragment.QueueShopFragment.TYPE_QUENE_WAIT;


/**
 * Created by uesr on 2018/8/10.
 */

public class QueueShopAdapter extends RecyclerViewAdapter<QueueShopAdapter.ViewHolder,QueueShops> {


    private int type;
    public QueueShopAdapter(Context context, int mType) {
        super(context, R.layout.item_queue_shop);
        this.type = mType;
    }

    @Override
    protected ViewHolder initViewHolder(View view, int i) {

        return new ViewHolder(view);
    }

    @Override
    protected void bindView(ViewHolder holder, final QueueShops data, int i) {

        if(getContext() != null){
            Glide.with(getContext())
                    .load(APIUrls.COMMON_CONFIG.TYPE_COMMON_ALIYUN+data.getLogoImg())
                    .dontAnimate()
                    .placeholder(R.mipmap.ic_wait_logo)
                    .error(R.mipmap.ic_error)
                    .into(holder.rvHead);
        }

        if(getContext() != null){
            Glide.with(getContext())
                    .load(APIUrls.COMMON_CONFIG.TYPE_COMMON_ALIYUN+data.getPrizeImg())
                    .dontAnimate()
                    .placeholder(R.mipmap.ic_wait_logo)
                    .error(R.mipmap.ic_error)
                    .into(holder.rvPrizeImg);
        }

        if(type == TYPE_QUENE_WAIT){
            if(data.isCurShopGood()){
                holder.rvHead.setVisibility(View.GONE);
                holder.tvName.setText("我的排队序号："+data.getSortNo());
                holder.tvStare.setText("前面等待商家数："+data.getWait());
                holder.tvStare.setSelected(false);
            }else {
                holder.rvHead.setVisibility(View.VISIBLE);
                holder.tvName.setText(data.getShopName());
                holder.tvStare.setText("序号："+data.getSortNo());
                holder.tvStare.setSelected(true);
            }
        }else {
            holder.rvHead.setVisibility(View.VISIBLE);
            holder.tvName.setText(data.getShopName());
            holder.tvStare.setText("序号："+data.getSortNo());
            holder.tvStare.setSelected(true);
        }




        holder.tvGoodsName.setText(data.getPrizeTitle());
        holder.tvMoeny.setText(StockUtils.moenyStyleNoZero(data.getProPrice()+""));

    }


    public class ViewHolder extends RecyclerViewAdapter.ViewHolder {

        @BindView(R.id.item_queue_shop_tv_name)
        TextView tvName;
        @BindView(R.id.item_queue_shop_tv_state)
        TextView tvStare;
        @BindView(R.id.item_queue_shop_tv_goods_name)
        TextView tvGoodsName;
        @BindView(R.id.item_queue_shop_tv_money)
        TextView tvMoeny;



        @BindView(R.id.item_queue_shop_rv_head)
        RoundImageView rvHead ;
        @BindView(R.id.item_queue_shop_rv_prize_img)
        RoundImageView rvPrizeImg ;



        public ViewHolder(View itemView) {
            super(itemView);
        }
    }



    public void setOnQueueShopListener(OnQueueShopListener onQueueShopListener) {
        this.listener = onQueueShopListener;
    }

    private OnQueueShopListener listener;

    public interface OnQueueShopListener {

      //  void onJoinClick(ManageEventData ManageEventData);

    }

}
